precision mediump float;

uniform sampler2D u_samplerColor;
uniform sampler2D u_samplerColor2;
uniform sampler2D u_samplerDepth;
uniform float u_saturation;

varying vec2 v_uv;

void main()
{
	vec3 tex = texture2D(u_samplerColor, v_uv).rgb;
	vec3 texBlur = texture2D(u_samplerColor2, v_uv).rgb;
	float texDepth = texture2D(u_samplerDepth, v_uv).r;
	
	float near = 1.0;
	float far = 10000.0;
	
	float z = -far * near / (texDepth * (far - near) - far);
	float clarity = near + u_saturation * (far - near);
	float k = clamp(abs(z - clarity)/20.0, 0.0, 1.0);
	gl_FragColor = vec4(mix(tex, texBlur, k), 1.0);
}
